
#include <iostream>
#include <fstream>
#include <cassert>
#include "sqlist.h"

using namespace std;

typedef int elemtype;
typedef sqlisttpl<elemtype> sqlist;

void insert( sqlist &, elemtype );

int main()
{
    ifstream in( "in01.txt" );
    int i, n;

    in >> n;
    sqlist va(n);
    for ( i = 0; i < n; i++ )
	in >> va[i];

    va.sq_print(); cout << endl;
    insert( va, 4 );
    va.sq_print(); cout << endl;

    return 0;
}

/* ******************************************************
 *             Answer to this question.
 * ******************************************************/

void insert( sqlist &va, elemtype x )
{
    int i;

    va.sq_inc(1);
    for( i = va.sq_len() - 2; i >= 0 && va[i] > x; i-- )
	va[i+1] = va[i];
    va[i+1] = x;
    
    return;
}
